#!/bin/bash

#Created by turk 2016-10-25
#Version 1.0 



#if [ $# -lt 2 ]; then
#	echo `date +"%Y-%m-%d %H:%M:%S"`  "Usage:<TABLE1> <TABLE2>"
#	exit 1
#fi

#TABLE1=$1
#TABLE2=$2

WORKPATH=/home/hadoop/work/
JAVALIB=${WORKPATH}/lib/
LOGFILE=${WORKPATH}/log/vio_data_syn.log


echo `date +"%Y-%m-%d %H:%M:%S"`  "-----------------------------" | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "Shell Version 1.0 (2016-10-25)"     | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "UBAS-VIO DATA SYN"  | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "-----------------------------"  | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "Start..."  | tee -a $LOGFILE

#2016-12-06 modified by turk remove ip format function

DBIP=192.168.5.25

export HADOOP_CLASSPATH=$JAVALIB/ojdbc14.jar

hadoop fs -rm -r hdfs://nameservice1/user/hive/warehouse/vio.db/vio_flowmirror_task
sqoop import  -D oracle.sessionTimeZone=CST --connect jdbc:oracle:thin:@${DBIP}:1521:BSMP \
--username vio --password=h16aug8v3w -m 1 \
--query 'select * from vio_flowmirror_task where STATUS!=3 and $CONDITIONS' \
--as-textfile --fields-terminated-by  ','  \
--target-dir '/user/hive/warehouse/vio.db/vio_flowmirror_task' \
--hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' \
--hive-overwrite > $LOGFILE 2>&1


hadoop fs -rm -r hdfs://nameservice1/user/hive/warehouse/vio.db/vio_flowmirror_ipseg
#sqoop import  -D oracle.sessionTimeZone=CST --connect jdbc:oracle:thin:@192.168.5.25:1521:BSMP \
#--username vio --password=h16aug8v3w --table VIO_FLOWMIRROR_IPSEG -m 1  --warehouse-dir /user/hive/warehouse/ \
#--hive-import --hive-database vio --hive-table vio_flowmirror_ipseg \
#--columns IPSEGID,TASKID,IPSEGMENT,IP2INT(STARTIP),IP2INT(ENDIP) \
#--as-textfile --fields-terminated-by  ',' --where 'TASKID IN (SELECT TASKID FROM VIO_FLOWMIRROR_TASK WHERE STATUS != 3)' \
#--hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' \
#--hive-overwrite --map-column-hive SCORE=bigint > $LOGFILE 2>&1

sqoop import -D oracle.sessionTimeZone=CST --connect jdbc:oracle:thin:@${DBIP}:1521:BSMP \
--username vio --password=h16aug8v3w -m 1 \
--query 'select IPSEGID,TASKID,IPSEGMENT,IP2INT(STARTIP),IP2INT(ENDIP) from VIO_FLOWMIRROR_IPSEG where TASKID IN (SELECT TASKID FROM VIO_FLOWMIRROR_TASK WHERE STATUS != 3) and $CONDITIONS' \
--as-textfile --fields-terminated-by  ',' \
--target-dir '/user/hive/warehouse/vio.db/vio_flowmirror_ipseg' \
--hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' --hive-overwrite > $LOGFILE 2>&1


echo `date +"%Y-%m-%d %H:%M:%S"`      "Quit" | tee -a $LOGFILE

exit 0
